|
|
|
|
|
|
|
Figure 21.5
Example from this chapters sample project to interact with the Clipboard. |
|
|
|
|
|
|
|
|
Many times youll want to control how the user selects text. For example, to perform a copy-and-paste operation, the user must first highlight all the text to be copied with the mouse. However, there may be times when you want to have that text highlighted automatically. You can set certain properties in text boxes that allow you to control the selection of text. These properties are SelStart, SelLength, and SelText. |
|
|
|
|
|
|
|
|
The SelStart property controls where the cursor is placed in the text box. It also marks the beginning of a block of text you want to mark. If you set SelStart to 0, the cursor is placed at the position prior to the first character in the text box. If you set it to the length of the string in the text box, its positioned at the character after the string in the text box. |
|
|
|
|
|
|
|
|
The SelLength property controls how many characters are marked after the start of the block. For example, if you set SelStart to 0 and SelLength to 5, the first six characters will be highlighted and can be copied to the Clipboard with the Ctrl+C key combination. |
|
|
|
|
|
|
|
|
The SelText property contains the text thats highlighted using the SelStart and SelLength properties. You can read and write to this property at runtime. |
|
|
|
|
|
|
|
|
Moving Text to the Clipboard |
|
|
|
|
|
|
|
|
Once you have the text highlighted, you can then use the Clipboard object to transfer data to and from the Windows Clipboard. The three methods used most often are Clear(), SetText(), and GetText(). The Clear method empties the Clipboard. The SetText method transfers data to the Clipboard. The GetText method retrieves data from the Clipboard. Heres some code that illustrates these methods: |
|
|
|
 |
|
|
|
|
Private Sub tlbTools_ButtonClick(ByVal Button As _
ComctlLib.Button) |
|
|
|
|
|